/**
 * This class provides the modal Ext.Window support for all Authentication forms.
 * It's layout is structured to center any Authentication dialog within it's center,
 * and provides a backGround image during such operations.
 */
Ext.define('Monkey.view.menu.MenuWindow', {
    extend: 'Ext.window.Window',
    xtype: 'menuwindow',

    requires: [
        'Monkey.view.menu.MenuController',
        'Monkey.view.menu.MenuModel',
        'Ext.ux.TreePicker'
    ],

    controller: 'ctrl-menutree',
    viewModel: 'vm-menutree',
    closable: true,
    resizable: false,
    constrain: true,
    constrainHeader: true,
    modal: true,
    frameHeader: false,
    frame: true,
    maximizable: false,
    layout: 'fit',
    width: 360,
    height: 350,
    initComponent: function () {
        var form = {
            xtype: 'form',
            border: false,
            buttonAlign: 'center',
            reference: 'form',
            layout: 'form',
            bodyStyle: 'padding:15px 5px 0 5px',
            defaults: {
                labelWidth: 80,
                labelAlign: 'right'/*,
                 msgTarget: 'side'*/
            },
            defaultType: 'textfield',
            buttons: [{
                //formBind: true,
                text: '确定',
                iconCls: 'accept',
                handler: 'ok'
            }, {
                text: '取消',
                iconCls: 'delete',
                handler: 'winCancel'
            }]
        };

        var store = Ext.create('Monkey.store.BaseTreeStore', {
            nodeParam: 'parentId',
            defaultRootId: '1',
            root: {
                expanded: true
            },
            fields: [
                {name: 'id', type: 'int'},
                {name: 'leaf', type: 'boolean'},
                {name: 'name', type: 'string'},
                {name: 'icon', type: 'string'},
                {name: 'expanded', type: 'boolean', mapping: 'expand'}
            ],
            proxy: {
                type: 'ajax',
                url: Monkey.URL.SERVER_URL + "/m/menu_list.json",
                extraParams: {
                    fields: 'id,leaf,name,icon,expand'
                },
                reader: 'json'
            }
        });

        form.items = [{
            editable: false,
            xtype: 'treepicker',
            rootVisible: false,
            allowBlank: false,
            fieldLabel: '<span style="color: red;">*</span>上级菜单',
            displayField: 'name',
            name: 'parentId',
            minPickerHeight: 250,
            bind: '{parentId}',
            useArrows: true,
            store: store
        }, {
            bind: '{name}',
            name: 'name',
            maxLength: '10',
            allowBlank: false,
            fieldLabel: '<span style="color: red;">*</span>菜单名'
        }, {
            bind: '{identity}',
            name: 'identity',
            maxLength: '15',
            allowBlank: false,
            fieldLabel: '<span style="color: red;">*</span>权限标识'
        }, {
            bind: '{view}',
            name: 'view',
            maxLength: '30',
            allowBlank: false,
            fieldLabel: '<span style="color: red;">*</span>view组件名'
        }, {
            bind: '{icon}',
            name: 'icon',
            maxLength: '50',
            allowBlank: false,
            fieldLabel: '<span style="color: red;">*</span>图标'
        }, {
            bind: '{expand}',
            name: 'expand',
            xtype: 'combobox',
            editable: false,
            allowBlank: false,
            fieldLabel: '默认展开',
            displayField: 'label',
            valueField: 'value',
            store: Monkey.Config.booleanStore
        }, {
            bind: '{status}',
            name: 'status',
            xtype: 'combobox',
            allowBlank: false,
            editable: false,
            fieldLabel: '状态',
            displayField: 'label',
            valueField: 'value',
            store: Monkey.Config.statusStore
        }, {
            bind: '{weight}',
            name: 'weight',
            xtype: 'numberfield',
            allowBlank: false,
            fieldLabel: '<span style="color: red;">*</span>排序'
        }, {
            bind: '{id}',
            name: 'id',
            xtype: 'hidden'
        }];

        this.items = [form];
        this.callParent();
    }
});
